package com.beiye.drivertransport.SubActivity;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.android.frame.adapter.CommonAdapter;
import com.android.frame.adapter.ViewHolder;
import com.beiye.drivertransport.R;
import com.beiye.drivertransport.activity.TwoBaseAty;
import com.beiye.drivertransport.bean.CarBean;
import com.beiye.drivertransport.bean.CheckBean;
import com.beiye.drivertransport.bean.DailyPriceBean;
import com.beiye.drivertransport.bean.IllegalLearningPaymentBean;
import com.beiye.drivertransport.bean.LoginUserBean;
import com.beiye.drivertransport.bean.TrainingIndvPriceFindBean;
import com.beiye.drivertransport.bean.TypesofViolationBean;
import com.beiye.drivertransport.bean.UserVipCheckBean;
import com.beiye.drivertransport.config.AppInterfaceConfig;
import com.beiye.drivertransport.http.Login;
import com.beiye.drivertransport.safelearn.SpecifiedLearningHomeActivity;
import com.beiye.drivertransport.utils.HelpUtil;
import com.beiye.drivertransport.utils.TiShiDialog;
import com.beiye.drivertransport.utils.UserManger;
import com.beiye.drivertransport.utils.Utils;
import com.githang.statusbar.StatusBarCompat;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;

import java.util.ArrayList;
import java.util.List;


import butterknife.OnClick;
import okhttp3.Call;
import okhttp3.Response;

//违章培训种类申请界面
public class TypesofViolationTrainingActivity extends TwoBaseAty {

    ImageView img_illegalback;//返回

    TextView tv_title;

    ListView lv_typesof;

    View empty_view;
    ArrayList<TypesofViolationBean.RowsBean> typesoflist = new ArrayList<>();
    private IllegalLearningApt illegalLearningApt;
    ArrayList<CarBean.RowsBean> carList = new ArrayList<>();
    private PopupWindow mPlatoPopWindow;
    private PopupWindow mNoPopWindow;
    private EditText ed_id;
    private SubtypeCarApt subtypeCarApt;
    private EditText ed_car;
    private String jumpType;
    private boolean checkResult;  //是否是会员标识
    private boolean buyMember;
    private String orgId;

    @Override
    public int getLayoutId() {
        return R.layout.activity_typesof_violation_training;
    }

    public void onClick(View view) {
        if (view.getId() == R.id.img_illegalback) {
            finish();
        }
    }

    @Override
    public void initData() {
        img_illegalback = (ImageView)findViewById(R.id.img_illegalback);
        tv_title = (TextView) findViewById(R.id.tv_title);
        lv_typesof = (ListView) findViewById(R.id.lv_typesof);
        empty_view = (View) findViewById(R.id.empty_view);

        StatusBarCompat.setStatusBarColor(this, Color.parseColor("#1F80C4"));
        lv_typesof.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (Utils.isFastClicker()) {
                    return;
                }
                SharedPreferences sp = getSharedPreferences("TypesofViolationTrainingActivity", Context.MODE_PRIVATE);
                int sn = illegalLearningApt.getItem(position).getSn();
                String orgId = sp.getString("orgId", "");
                plateNumber(orgId, sn);//查询车辆
            }
        });


    }

    @Override
    public void requestData() {

        Bundle bundle = getIntent().getExtras();
        orgId = bundle.getString("orgId");
        String adId = bundle.getString("adId");
        jumpType = bundle.getString("jumpType");

        if (jumpType.equals("homeFgt")) {
            tv_title.setText("申请违章培训种类");
        } else {
            tv_title.setText("申请信用修复");
        }

        SharedPreferences sp = getSharedPreferences("TypesofViolationTrainingActivity", Context.MODE_PRIVATE);
        SharedPreferences.Editor edit = sp.edit();
        edit.putString("orgId", orgId);
        edit.commit();
        LoginUserBean userInfo = UserManger.getUserInfo();
        LoginUserBean.DataBean data = userInfo.getData();
        String userId = data.getUserId();

        //江苏使用orgId   驾运宝使用adid
        new Login().getUserViolationtraining(orgId, userId, this, 3);//查询违章培训价格
        showLoadingDialog("");
        new Login().getIllegalTypeData(orgId, 1, this, 1);

        //new Login().userVipCheck(userId, orgId, this, 4);  //校验用户是否在会员期内

        //new Login().trainingIndvPriceFind(orgId, TypesofViolationTrainingActivity.this, 5); //获取会员方案列表
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        SharedPreferences sp = getSharedPreferences("TypesofViolationTrainingActivity",
                Context.MODE_PRIVATE);
        SharedPreferences.Editor edit = sp.edit();
        edit.clear();
        edit.commit();
        if (mPlatoPopWindow != null) {
            mPlatoPopWindow.dismiss();
        }
        if (mNoPopWindow != null) {
            mNoPopWindow.dismiss();
        }
    }

    @Override
    protected void onResume() {
        super.onResume();

        requestData();
    }

    @Override
    public void onSuccess(String result, Call call, Response response, int what) {
        super.onSuccess(result, call, response, what);
        if (what == 1) {
            dismissLoadingDialog();
            TypesofViolationBean typesofViolationBean = JSON.parseObject(result, TypesofViolationBean.class);
            List<TypesofViolationBean.RowsBean> rows = typesofViolationBean.getRows();
            typesoflist.clear();
            if (rows.size() == 0) {
                lv_typesof.setEmptyView(empty_view);
                lv_typesof.setAdapter(null);
                return;
            }
            typesoflist.addAll(rows);
            illegalLearningApt = new IllegalLearningApt(TypesofViolationTrainingActivity.this, typesoflist);
            lv_typesof.setAdapter(illegalLearningApt);
        } else if (what == 2) {
            showToast("申请成功");
            dismissLoadingDialog();

            IllegalLearningPaymentBean illegalLearningPaymentBean = JSON.parseObject(result, IllegalLearningPaymentBean.class);
            Integer uvtSn = illegalLearningPaymentBean.getData();
            Bundle bundle = new Bundle();
            bundle.putInt("uvtSn", uvtSn);
            bundle.putString("jumpType", "homeFgt");
            startActivity(SubIllegalLearningActivity.class, bundle);
            finish();
        } else if (what == 3) {

            DailyPriceBean mineUseBean = JSON.parseObject(result, DailyPriceBean.class);
            DailyPriceBean.DataBean dailydata = mineUseBean.getData();
            float balance = dailydata.getBalance();
            float vtPirce = dailydata.getVtPirce();
            SharedPreferences sp1 = getSharedPreferences("TypesofViolationTrainingActivity", Context.MODE_PRIVATE);
            SharedPreferences.Editor edit = sp1.edit();
            edit.putFloat("balance", balance);
            edit.putFloat("vtPirce", vtPirce);
            edit.commit();
        } else if (what == 4) {
            UserVipCheckBean bean = JSON.parseObject(result, UserVipCheckBean.class);
            checkResult = bean.isResult();
        }else if(what== 5){
            TrainingIndvPriceFindBean bean = JSON.parseObject(result, TrainingIndvPriceFindBean.class);
            List<TrainingIndvPriceFindBean.RowsBean> rowsBeans = bean.getRows();
            if(rowsBeans==null || rowsBeans.size()<=0){
                buyMember=false;
            }else{
                buyMember=true;
            }
        }
    }

    @Override
    public void onError(String result, Call call, Response response, int what) {
        super.onError(result, call, response, what);
        if (what == 2) {
            dismissLoadingDialog();
            CheckBean checkBean = JSON.parseObject(result, CheckBean.class);
            String msg = checkBean.getMsg();
            TiShiDialog.Builder builder = new TiShiDialog.Builder(this);
            builder.setMessage(msg);
            builder.setTitle("提示:");
            builder.setPositiveButton("我知道啦", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();

                }
            });
            builder.create().show();
        } else if (what == 4) {
            UserVipCheckBean bean = JSON.parseObject(result, UserVipCheckBean.class);
            checkResult = bean.isResult();
        }
    }

    public class IllegalLearningApt extends BaseAdapter {
        private Context ctx;
        private LayoutInflater li;
        private ArrayList<TypesofViolationBean.RowsBean> dataList;


        public IllegalLearningApt(Context ctx, ArrayList<TypesofViolationBean.RowsBean> dataList) {
            this.ctx = ctx;
            this.li = LayoutInflater.from(ctx);
            this.dataList = dataList;
        }

        @Override
        public int getCount() {
            return dataList.size();
        }

        @Override
        public TypesofViolationBean.RowsBean getItem(int position) {
            return dataList.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            if (convertView == null) {
                convertView = View.inflate(ctx, R.layout.typesof_item_layout, null);
                new IllegalLearningApt.ViewHolder(convertView);
            }
            IllegalLearningApt.ViewHolder holder = (IllegalLearningApt.ViewHolder) convertView.getTag();// get convertView's holder
            String vttName = getItem(position).getVttName();
            int courseNo = getItem(position).getCourseNo();
            int courseLength = getItem(position).getCourseLength();
            final int sn = getItem(position).getSn();
            if (vttName == null) {
                holder.tv_name.setText("");

            } else {

                holder.tv_name.setText(getItem(position).getVttName());

            }
            if (courseNo == 0) {
                holder.tv_num.setText(0 + "个");

            } else {
                holder.tv_num.setText(getItem(position).getCourseNo() + "个");

            }
            if (courseLength == 0) {
                holder.tv_courseLength.setText(0 + "分钟");

            } else {
                holder.tv_courseLength.setText(getItem(position).getCourseLength() + "分钟");

            }

            final TextView tv_apply = holder.tv_Apply;
            tv_apply.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (Utils.isFastClicker()) {
                        return;
                    }
                    SharedPreferences sp = getSharedPreferences("TypesofViolationTrainingActivity",
                            Context.MODE_PRIVATE);
                    String orgId = sp.getString("orgId", "");
                    plateNumber(orgId, sn);//查询车辆

                }
            });
            return convertView;
        }

        class ViewHolder {
            TextView tv_Apply;
            TextView tv_courseLength;
            TextView tv_num;
            TextView tv_name;

            public ViewHolder(View convertView) {
                tv_name = (TextView) convertView.findViewById(R.id.tv_typesof);
                tv_num = (TextView) convertView.findViewById(R.id.tv_typesof2);
                tv_courseLength = (TextView) convertView.findViewById(R.id.tv_typesof4);
                tv_Apply = (TextView) convertView.findViewById(R.id.tv_typesof5);
                convertView.setTag(this);
            }
        }

    }

    private void plateNumber(final String orgId, final int sn) {
        LoginUserBean userInfo = UserManger.getUserInfo();
        LoginUserBean.DataBean data = userInfo.getData();
        String userId = data.getUserId();
        //查询车牌号
        OkGo.get(AppInterfaceConfig.BASE_URL + "sys/vehicleOrg/getVehicles/" + userId)
                .tag(this)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(String result, Call call, Response response) {

                        CarBean carBean = JSON.parseObject(result, CarBean.class);
                        List<CarBean.RowsBean> rows = carBean.getRows();
                        if (rows.size() == 0) {

                            shownoPlatoPopwindow(sn, orgId);
                            return;
                        }
                        carList.clear();
                        for (int i = 0; i < rows.size(); i++) {
                            if (rows.get(i).getOrgId().equals(orgId)) {
                                carList.add(rows.get(i));
                            }
                        }
                        if (carList.size() == 0) {
                            shownoPlatoPopwindow(sn, orgId);
                            return;

                        } else {
                            carList.get(0).setChecked(true);
                            subtypeCarApt = new SubtypeCarApt(TypesofViolationTrainingActivity.this, carList, R.layout.car_item_layout);
                            if (subtypeCarApt == null || subtypeCarApt.getCount() == 0) {
                                shownoPlatoPopwindow(sn, orgId);
                                return;
                            } else {
                                showPlatoPopwindow(sn, orgId);
                            }

                        }

                    }

                    @Override
                    public void onError(Call call, Response response, Exception e) {
                        super.onError(call, response, e);

                    }
                });


    }

    private void showPlatoPopwindow(final int sn, final String orgId) {
        SharedPreferences sp = getSharedPreferences("MessageEvent12",
                Context.MODE_PRIVATE);
        SharedPreferences.Editor edit = sp.edit();
        edit.clear();
        edit.commit();
        //设置contentView
        View contentView = LayoutInflater.from(TypesofViolationTrainingActivity.this).inflate(R.layout.typesofviolation_popwindow, null);
        mPlatoPopWindow = new PopupWindow(contentView,
                WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, true);
        //设置各个控件的点击响应
        RelativeLayout car_re2 = (RelativeLayout) contentView.findViewById(R.id.car_re2);
        ListView lv_car = (ListView) contentView.findViewById(R.id.lv_car1);
        lv_car.setAdapter(subtypeCarApt);

        if (subtypeCarApt.getCount() == 1) {
            ViewGroup.LayoutParams params = car_re2.getLayoutParams();
            params.height = 150;
            car_re2.setLayoutParams(params);
        } else if (subtypeCarApt.getCount() == 2) {
            ViewGroup.LayoutParams params = car_re2.getLayoutParams();
            params.height = 300;
            car_re2.setLayoutParams(params);
        } else if (subtypeCarApt.getCount() == 3) {
            ViewGroup.LayoutParams params = car_re2.getLayoutParams();
            params.height = 430;
            car_re2.setLayoutParams(params);
        } else if (subtypeCarApt.getCount() > 3) {
            ViewGroup.LayoutParams params = car_re2.getLayoutParams();
            params.height = 580;
            car_re2.setLayoutParams(params);
        }

        mPlatoPopWindow.showAtLocation(tv_title, Gravity.CENTER, 0, 0);
        TextView tv_ture = (TextView) contentView.findViewById(R.id.tv_two_sure);
        ImageView img_gone = (ImageView) contentView.findViewById(R.id.img_gone);

        ed_car = (EditText) contentView.findViewById(R.id.ed_car);
        // 编辑框设置触摸监听
        ed_car.setOnTouchListener(new View.OnTouchListener() {

            @SuppressLint("ClickableViewAccessibility")
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (MotionEvent.ACTION_DOWN == event.getAction()) {
                    ed_car.setCursorVisible(true);// 再次点击显示光标
                }
                return false;
            }
        });

        tv_ture.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SharedPreferences sp = getSharedPreferences("MessageEvent12",
                        Context.MODE_PRIVATE);
                String plateNo = sp.getString("plateNo", "");
                LoginUserBean userInfo = UserManger.getUserInfo();
                LoginUserBean.DataBean data = userInfo.getData();
                String userId = data.getUserId();
                String carwtr = ed_car.getText().toString().trim();
                SharedPreferences sp1 = getSharedPreferences("TypesofViolationTrainingActivity", Context.MODE_PRIVATE);
                float balance = sp1.getFloat("balance", 0);
                float vtPirce = sp1.getFloat("vtPirce", 0);


                if (carwtr.equals("")) {
                    if (plateNo.equals("")) {
                        Toast.makeText(TypesofViolationTrainingActivity.this, "请选中车牌号", Toast.LENGTH_SHORT).show();
                        return;
                    }
                    mPlatoPopWindow.dismiss();

                    if(checkResult){
                        new Login().userViolationTrainingAdd(userId,orgId,plateNo,sn,TypesofViolationTrainingActivity.this,2);
                    }else{
                        if (vtPirce == 0)//违章培训免费
                        {
                            showLoadingDialog("");

                            SharedPreferences dishSp = getSharedPreferences("BusinessSelfinspectionDishinfoActivity", Context.MODE_PRIVATE);
                            String discreditId = dishSp.getString("discreditId", "");
                            String discreditType = dishSp.getString("discreditType", "");
                            String depName = dishSp.getString("depName", "");
                            String discreditContent = dishSp.getString("discreditContent", "");

                            SharedPreferences eduListSp = getSharedPreferences("BusinessSelfinspectionScoreEducListActivity", Context.MODE_PRIVATE);
                            String scoreEducId = eduListSp.getString("scoreEducId", "");

                            if (jumpType.equals("homeFgt")) {
                                new Login().getViolationtrainingPayMentApp(userId, orgId, plateNo, sn, TypesofViolationTrainingActivity.this, 2);//车牌号
                            } else if (jumpType.equals("dish")) {
                                new Login().vioTrainApplyByDiscreditId(orgId, userId, plateNo, sn + "", depName, discreditType, discreditId, discreditContent, TypesofViolationTrainingActivity.this, 2);
                            } else if (jumpType.equals("eduList")) {
                                new Login().vioTrainApplyByScoreEducId(orgId, userId, plateNo, sn + "", scoreEducId, TypesofViolationTrainingActivity.this, 2);
                            }

                        } else if (vtPirce > 0) {  //违章培训需付费
                            /*if(buyMember){
                                TiShiDialog.Builder builder1 = new TiShiDialog.Builder(TypesofViolationTrainingActivity.this);
                                builder1.setMessage("您所属企业需购买包月会员");
                                builder1.setTitle("提示:");
                                builder1.setPositiveButton("买会员", new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int which) {
                                        dialog.dismiss();
                                        //startActivity(MemberInfoActivity.class, null);
                                        startActivity(MemberMsgActivity.class,null);
                                    }
                                });
                               *//* builder1.setNegativeButton("取消",
                                        new android.content.DialogInterface.OnClickListener() {
                                            public void onClick(DialogInterface dialog, int which) {
                                                dialog.dismiss();
                                            }
                                        });*//*

                                builder1.create().show();
                                return;
                            }else{

                            }*/
                            Bundle bundle = new Bundle();
                            bundle.putString("orgId", orgId);
                            bundle.putFloat("vtPirce", vtPirce);
                            bundle.putFloat("balance", balance);
                            bundle.putString("plateNo", plateNo);
                            bundle.putInt("sn", sn);
                            bundle.putString("jumpType", jumpType);
                            startActivity(IllegalLearningPaymentActivity.class, bundle);
                            finish();
                        }
                    }



                } else {
                    mPlatoPopWindow.dismiss();
                    if(checkResult){
                        new Login().userViolationTrainingAdd(userId,orgId,carwtr,sn,TypesofViolationTrainingActivity.this,2);
                    }else{
                        if (vtPirce == 0)//违章培训免费
                        {
                            showLoadingDialog("");
                            SharedPreferences dishSp = getSharedPreferences("BusinessSelfinspectionDishinfoActivity", Context.MODE_PRIVATE);
                            String discreditId = dishSp.getString("discreditId", "");
                            String discreditType = dishSp.getString("discreditType", "");
                            String depName = dishSp.getString("depName", "");
                            String discreditContent = dishSp.getString("discreditContent", "");

                            SharedPreferences eduListSp = getSharedPreferences("BusinessSelfinspectionScoreEducListActivity", Context.MODE_PRIVATE);
                            String scoreEducId = eduListSp.getString("scoreEducId", "");

                            if (jumpType.equals("homeFgt")) {
                                new Login().getViolationtrainingPayMentApp(userId, orgId, plateNo, sn, TypesofViolationTrainingActivity.this, 2);//车牌号
                            } else if (jumpType.equals("dish")) {
                                new Login().vioTrainApplyByDiscreditId(orgId, userId, plateNo, sn + "", depName, discreditType, discreditId, discreditContent, TypesofViolationTrainingActivity.this, 2);
                            } else if (jumpType.equals("eduList")) {
                                new Login().vioTrainApplyByScoreEducId(orgId, userId, plateNo, sn + "", scoreEducId, TypesofViolationTrainingActivity.this, 2);
                            }
                        } else if (vtPirce > 0) {
                            /*if(buyMember) {
                                TiShiDialog.Builder builder1 = new TiShiDialog.Builder(TypesofViolationTrainingActivity.this);
                                builder1.setMessage("您所属企业需购买包月会员");
                                builder1.setTitle("提示:");
                                builder1.setPositiveButton("买会员", new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int which) {
                                        dialog.dismiss();
                                        //startActivity(MemberInfoActivity.class, null);
                                        startActivity(MemberMsgActivity.class,null);
                                    }
                                });
                               *//* builder1.setNegativeButton("取消",
                                        new android.content.DialogInterface.OnClickListener() {
                                            public void onClick(DialogInterface dialog, int which) {
                                                dialog.dismiss();
                                            }
                                        });*//*

                                builder1.create().show();
                                return;
                            }*/
                            Bundle bundle = new Bundle();
                            bundle.putString("orgId", orgId);
                            bundle.putFloat("vtPirce", vtPirce);
                            bundle.putFloat("balance", balance);
                            bundle.putString("plateNo", carwtr);
                            bundle.putInt("sn", sn);
                            bundle.putString("jumpType", jumpType);
                            startActivity(IllegalLearningPaymentActivity.class, bundle);
                            finish();
                        }
                    }
                }
                SharedPreferences.Editor edit = sp.edit();
                edit.clear();
                edit.commit();

            }
        });
        img_gone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mPlatoPopWindow.dismiss();
                SharedPreferences sp = getSharedPreferences("MessageEvent12",
                        Context.MODE_PRIVATE);
                SharedPreferences.Editor edit = sp.edit();
                edit.clear();
                edit.commit();
            }
        });

    }

    private void shownoPlatoPopwindow(final int sn, final String orgId) {

        View contentView = LayoutInflater.from(TypesofViolationTrainingActivity.this).inflate(R.layout.notypesofviolation_popwindowlayout, null);
        mNoPopWindow = new PopupWindow(contentView,
                WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, true);
        ed_id = (EditText) contentView.findViewById(R.id.ed_id);
        mNoPopWindow.showAtLocation(tv_title, Gravity.CENTER, 0, 0);
// 编辑框设置触摸监听
        ed_id.setOnTouchListener(new View.OnTouchListener() {

            @SuppressLint("ClickableViewAccessibility")
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (MotionEvent.ACTION_DOWN == event.getAction()) {
                    ed_id.setCursorVisible(true);// 再次点击显示光标
                }
                return false;
            }
        });
        ImageView img_gone = (ImageView) contentView.findViewById(R.id.img_gone);
        img_gone.setVisibility(View.VISIBLE);
        TextView tv_idsave = (TextView) contentView.findViewById(R.id.tv_idsave);
        tv_idsave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String Plato = ed_id.getText().toString().trim();
                if (Plato.equals("")) {
                    showToast("车牌号不为空");
                    return;
                }
                mNoPopWindow.dismiss();


                SharedPreferences sp1 = getSharedPreferences("TypesofViolationTrainingActivity",
                        Context.MODE_PRIVATE);
                float balance = sp1.getFloat("balance", 0);
                float vtPirce = sp1.getFloat("vtPirce", 0);
                LoginUserBean userInfo = UserManger.getUserInfo();
                LoginUserBean.DataBean data = userInfo.getData();
                String userId = data.getUserId();

                if(checkResult){
                    new Login().userViolationTrainingAdd(userId,orgId,Plato,sn,TypesofViolationTrainingActivity.this,2);
                }else{
                    if (vtPirce == 0)//违章培训免费
                    {
                        showLoadingDialog("");
                        SharedPreferences dishSp = getSharedPreferences("BusinessSelfinspectionDishinfoActivity", Context.MODE_PRIVATE);
                        String discreditId = dishSp.getString("discreditId", "");
                        String discreditType = dishSp.getString("discreditType", "");
                        String depName = dishSp.getString("depName", "");
                        String discreditContent = dishSp.getString("discreditContent", "");

                        SharedPreferences eduListSp = getSharedPreferences("BusinessSelfinspectionScoreEducListActivity", Context.MODE_PRIVATE);
                        String scoreEducId = eduListSp.getString("scoreEducId", "");

                        if (jumpType.equals("homeFgt")) {
                            new Login().getViolationtrainingPayMentApp(userId, orgId, Plato, sn, TypesofViolationTrainingActivity.this, 2);//车牌号
                        } else if (jumpType.equals("dish")) {
                            new Login().vioTrainApplyByDiscreditId(orgId, userId, Plato, sn + "", depName, discreditType, discreditId, discreditContent, TypesofViolationTrainingActivity.this, 2);
                        } else if (jumpType.equals("eduList")) {
                            new Login().vioTrainApplyByScoreEducId(orgId, userId, Plato, sn + "", scoreEducId, TypesofViolationTrainingActivity.this, 2);
                        }
                    } else if (vtPirce > 0) {
                        /*if(buyMember) {
                            TiShiDialog.Builder builder1 = new TiShiDialog.Builder(TypesofViolationTrainingActivity.this);
                            builder1.setMessage("您所属企业需购买包月会员");
                            builder1.setTitle("提示:");
                            builder1.setPositiveButton("买会员", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                    //startActivity(MemberInfoActivity.class, null);
                                    startActivity(MemberMsgActivity.class,null);
                                }
                            });
                               *//* builder1.setNegativeButton("取消",
                                        new android.content.DialogInterface.OnClickListener() {
                                            public void onClick(DialogInterface dialog, int which) {
                                                dialog.dismiss();
                                            }
                                        });*//*

                            builder1.create().show();
                            return;
                        }*/
                        Bundle bundle = new Bundle();
                        bundle.putString("orgId", orgId);
                        bundle.putFloat("vtPirce", vtPirce);
                        bundle.putFloat("balance", balance);
                        bundle.putString("plateNo", Plato);
                        bundle.putInt("sn", sn);
                        bundle.putString("jumpType", jumpType);
                        startActivity(IllegalLearningPaymentActivity.class, bundle);
                        finish();
                    }
                }


            }
        });
        img_gone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mNoPopWindow.dismiss();
            }
        });
    }

    public class SubtypeCarApt extends CommonAdapter<CarBean.RowsBean> {
        private final List<CarBean.RowsBean> mList;
        private Context context;
        // 标记用户当前选择
        private int index = -1;


        public SubtypeCarApt(Context context, List<CarBean.RowsBean> mList, int itemLayoutId) {
            super(context, mList, itemLayoutId);
            this.context = context;
            this.mList = mList;
        }

        @Override
        public void convert(ViewHolder holder, CarBean.RowsBean item, final int position) {
            final RadioButton tv_car = holder.getView(R.id.tv_car);
            final RadioGroup radio_car = holder.getView(R.id.radio_car);
            tv_car.setText(mList.get(position).getPlateNo());

            if (mList.get(position).isChecked()) {
                tv_car.setBackgroundResource(R.drawable.carbtnpress);  //选中项背景
                tv_car.setTextColor(context.getResources().getColor(R.color.white_name));
                ed_car.setText("");

                SharedPreferences sp = context.getSharedPreferences("MessageEvent12",
                        Context.MODE_PRIVATE);
                SharedPreferences.Editor editor = sp.edit();
                editor.putString("plateNo", carList.get(position).getPlateNo());
                editor.commit();
            } else {
                tv_car.setBackgroundResource(R.drawable.carbtn);  //其他项背景
                tv_car.setTextColor(context.getResources().getColor(R.color.project_blue));
            }


            ed_car.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                }

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {
                    if (s.toString().length() > 0) {
                        tv_car.setChecked(false);
                        tv_car.setBackgroundResource(R.drawable.carbtn);  //其他项背景
                        tv_car.setTextColor(context.getResources().getColor(R.color.project_blue));
                        SharedPreferences sp = context.getSharedPreferences("MessageEvent12",
                                Context.MODE_PRIVATE);
                        SharedPreferences.Editor editor = sp.edit();
                        editor.clear();
                        editor.commit();

                    }
                }

                @Override
                public void afterTextChanged(Editable s) {

                }

            });

            radio_car.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(RadioGroup group, int checkedId) {

                }
            });
            tv_car.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {

                    for (int j = 0; j < mList.size(); j++) {
                        if (j == position) {
                            mList.get(j).setChecked(true);
                        } else {
                            mList.get(j).setChecked(false);
                        }
                    }
                    notifyDataSetChanged();
                }
            });
        }


    }
}
